# 导入蓝图对象
from flask import request, render_template, jsonify
import datetime
from . import itransaction
import sqlconfig as Isql
from util import IRequestUtil

@itransaction.route("/search")
def search():
    #拿到分页参数
    pageParam=IRequestUtil.pageParam()
    conn=Isql.defaultconfig("tbs-2")
    result=Isql.selectRows("select * from ttrd_trade ",conn)
    resp = list()
    for el in result:
        elem = {
            "tNumber": el[0],
            "tDirection": "债券买入" if(el[9]==1) else "债券卖出",
            #datetime.date(el[13]).strftime('%Y-%m-%d')
            "dealDate": el[13].strftime('%Y-%m-%d'),
            "mType": el[8],
            "iCode": el[4],
            "iName": el[5],
            "dealPaySum": float(el[12]),
            "couponAmount": float(el[14]),
            "dealAvgPrice": float(el[11]),
            "charge": float(el[10])
        }
        resp.append(elem)

    return jsonify(code="0", msg='OK', data=resp,count=1)
@itransaction.route("/index")
def index():
    conn = Isql.defaultconfig("tbs-2")
    result = Isql.selectRows("SELECT SECU_CODE as secuCode,SECU_NAME AS secuName FROM ttrd_acc_secu_mapping", conn)
    resp=list()
    for el in result:
        elem ={
            "secuCode": el[0],
            "secuName": el[1]
        }
        resp.append(elem)
    return jsonify(resp)